import request from "@/utils/request.js";

/**
 * 获取推荐文章列表
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const getRecommendedArticlesService = () => {
    return request.get('/articles/recommended');
}

/**
 * 获取文章列表
 * @param params
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const getArticleListService = (params) => {
    return request.get('/articles', { params });
}

/**
 * 创建文章
 * @param data
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const createArticleService = (data) => {
    return request.post('/articles', data);
}

/**
 * 获取文章分类列表
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const getCategoryListService = () => {
    return request.get('/categories');
}

/**
 * 新增文章分类
 * @param data
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const addCategoryService = (data) => {
    return request.post('/categories', data);
}

/**
 * 编辑文章分类
 * @param data
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const updateCategoryService = (data) => {
    return request.put('/categories', data);
}

/**
 * 删除文章分类
 * @param id
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const deleteCategoryService = (id) => {
    return request.delete(`/categories/${id}`);
}

/**
 * 更新文章
 * @param data
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const updateArticleService = (data) => {
    return request.put(`/articles/${data.id}`, data);
}

/**
 * 删除文章
 * @param id
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const deleteArticleService = (id) => {
    return request.delete(`/articles/${id}`);
}

 /**
  * 删除文章
  * @param {*} id 
  * @returns 
  */
export const deleteCategoryAliasService = (id) => {
    return request.delete(`/categories/${id}`);
}

/**
 * 获取文章统计数据
 * @param {number} days - 天数(7/15/30)
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const getArticleStatisticsService = (days) => {
    return request.get(`/articles/statistics?days=${days}`);
}

/**
 * 获取文章分类占比数据
 * @param {number} days - 天数(7/15/30)
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const getArticleCategoryStatsService = (days) => {
    return request.get(`/articles/category-stats?days=${days}`);
}

